package com.wocao.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wocao.entity.ReqBody;
import com.wocao.entity.SysDept;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * <p>
 * 部门表 Mapper 接口
 * </p>
 *
 * @since 2023-11-21
 */
@Mapper
public interface SysDeptMapper extends BaseMapper<SysDept> {

    //通过角色id查询部门id
    @Select("SELECT dept_id FROM `sys_role_dept` where role_id = #{roleId}")
    List<Long> selectDeptIdsByRoleId(long roleId);

    //通过角色id删除部门id
    @Delete("DELETE from sys_role_dept where role_id = #{roleId} ")
    void deleteDeptIdsByRoleId(long roleId);

    void addDeptIdsByRoleId(long roleId,Object[] deptIds);

    //分页查询+模糊匹配
    List<SysDept> selectDeptAll(@Param("deptName") String deptName, @Param("status") String status);

    //删除
    @Update("UPDATE sys_dept set del_flag = 2 where dept_id = #{deptId} ")
    void deleteDept(long deptId);

    //判断有没有未停用的子部门
    @Select("SELECT * FROM `sys_dept` where parent_id = #{deptId} and `status` = 0 ")
    List<SysDept> selectChildDept(long deptId);

    //判断当前部门的父部门是否启用
    @Select("SELECT * FROM `sys_dept` where dept_id = #{parentId} and `status` = 1 ")
    SysDept selectFatherDept(long parentId);
}
